package com.project.thisDatabase.elasticsearch.config;

import com.project.thisDatabase.elasticsearch.ElasticExecutor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

@ConditionalOnProperty(name = "spring.data.elasticsearch.enable", havingValue = "true")
@Component
public class InitConfig {

    @Autowired(required = false)
    ElasticExecutor elasticExecutor;

    @Autowired(required = false)
    ElasticInit elasticInit;

    @PostConstruct
    private void init(){
        try {
            elasticExecutor.createIndex();
            if (null != elasticInit){
                elasticInit.init();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

//        try {
//            Path file_path = Paths.get(f.getParent(), "search");
//        } catch (Exception e) {
//
//        }
    }
}
